<?php


error_reporting(0);


for ($ii = 0; $ii < 10000; $ii++) {
    $imagestring = getStr(4);

    $fontwidth  = imageFontWidth(5);
    $fontheight = imageFontHeight(5);
    $textwidth  = $fontwidth * strlen($imagestring);
    $textheight = $fontheight;

    $randimg = rand(1, 5);
    $im      = imagecreatefrompng("pic/regimages/reg" . $randimg . ".png");

    $imgheight = 40;
    $imgwidth  = 150;
    $textposh  = ($imgwidth - $textwidth) / 2;
    $textposv  = ($imgheight - $textheight) / 2;

    $dots = $imgheight * $imgwidth / 35;
    for ($i = 1; $i <= $dots; $i++) {
        imagesetpixel($im, rand(0, $imgwidth), rand(0, $imgheight), $textcolor);
    }

    $textcolor = imagecolorallocate($im, 0, 0, 0);
    imagestring($im, 5, $textposh, $textposv, $imagestring, $textcolor);

    imagejpeg($im, "images/" . strtolower(preg_replace('# #', '', $imagestring) . "_" . substr(md5($im . time()), 1, 16) . ".jpg"));
}


function getStr($num)
{
    $str    = "0123456789mddTYUIPASDFGHJKLZXCVBNM";
    $newStr = "";
    for ($i = 0; $i < $num; $i++) {
        $newStr .= " " . $str[mt_rand(0, strlen($str) - 1)];
    }
    return $newStr . " ";
}
